home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 48 / Amiga Format CD48 (1999-12-13)(Future Publishing)(GB)(Track 1 of 2)[!][issue 2000-01].iso / -serious- / programming / mui / mcc_transferanim / developer / c / examples / transferanim-demo.c
C/C++ Source or Header  |  1999-11-01  |  15KB  |  470 lines

  1. /***************************************************************************/
  2. /**                                                                       **/
  3. /**     TransferAnim-Demo, an example program for TransferAnim.mcc        **/
  4. /**                                                                       **/
  5. /**                                                                       **/
  6. /**     Feel free to use the source and please notify me about errors,    **/
  7. /**     bugs, good and bad things.                                        **/
  8. /**                                                                       **/
  9. /**     by Linus McCabe, sparkle@hehe.com                                 **/
  10. /**                      http://sparkle.amiga.tm                          **/
  11. /**                                                                       **/
  12. /***************************************************************************/
  13.  
  14. #define progname "TAnimExample"
  15. #define progbase "TANIME"
  16. #define vsion "V1.1 (15-May-99)"
  17.  
  18. #define aboutanim "mui:images/TransferAnim/aboutanim"
  19. #define aboutbutton "mui:images/TransferAnim/about"
  20. #define playbutton "mui:images/TransferAnim/play"
  21. #define stopbutton "mui:images/TransferAnim/stop"
  22. #define checkmark "mui:images/TransferAnim/checkmark"
  23. #define mainanim "mui:images/TransferAnim/mainanim"
  24.  
  25. /* System */
  26. #include <dos/dos.h>
  27. #include <workbench/workbench.h>
  28. #include <exec/memory.h>
  29. #include <libraries/mui.h>
  30. #include <datatypes/datatypes.h>
  31. #include <datatypes/pictureclass.h>
  32. #include <datatypes/PictureClassExt.h>
  33. #include <graphics/gfxmacros.h>
  34. #include <devices/timer.h>
  35. #include <libraries/asl.h>
  36. #include <mui/TransferAnim_mcc.h>
  37.  
  38. /* Prototypes */
  39.  
  40. #include <clib/alib_protos.h>
  41. #include <clib/exec_protos.h>
  42. #include <clib/dos_protos.h>
  43. #include <clib/icon_protos.h>
  44. #include <clib/graphics_protos.h>
  45. #include <clib/intuition_protos.h>
  46. #include <clib/gadtools_protos.h>
  47. #include <clib/utility_protos.h>
  48. #include <clib/asl_protos.h>
  49. #include <clib/muimaster_protos.h>
  50. #include <clib/datatypes_protos.h>
  51. #include <clib/rexxsyslib_protos.h>
  52.  
  53. /* ANSI C */
  54. #include <stdlib.h>
  55. #include <string.h>
  56. #include <stdio.h>
  57.  
  58. #ifdef __SASC
  59. #include <pragmas/exec_sysbase_pragmas.h>
  60. #else
  61. #include <pragmas/exec_pragmas.h>
  62. #endif
  63. #include <pragmas/dos_pragmas.h>
  64. #include <pragmas/icon_pragmas.h>
  65. #include <pragmas/graphics_pragmas.h>
  66. #include <pragmas/intuition_pragmas.h>
  67. #include <pragmas/gadtools_pragmas.h>
  68. #include <pragmas/utility_pragmas.h>
  69. #include <pragmas/asl_pragmas.h>
  70. #include <pragmas/muimaster_pragmas.h>
  71. #include <pragmas/rexxsyslib_pragmas.h>
  72.  
  73. extern struct Library *SysBase, *IconBase, *IntuitionBase, *GfxBase, *UtilityBase, *DOSBase; 
  74. extern struct Library * MUIMasterBase, *RexxSysBase, *AslBase;
  75.  
  76. __saveds __asm VOID aboutmui(register __a0 struct Hook *hook ,    register __a2 Object *appl ,    register __a1 APTR *args );
  77. __saveds __asm VOID about(register __a0 struct Hook *hook ,    register __a2 Object *appl ,    register __a1 APTR *args );
  78. __saveds __asm VOID closeabout(register __a0 struct Hook *hook ,    register __a2 Object *appl ,    register __a1 APTR *args );
  79.  
  80.  
  81. struct Library * MUIMasterBase;
  82.  
  83.   /*************************/
  84.  /* Menues                */
  85. /*************************/
  86.  
  87. enum { MenQuit=1, MenAbout, MenAboutMUI, MenMUIPrefs};
  88.  
  89. static const struct NewMenu MenuData1[] =
  90. {
  91. { NM_TITLE, progname                   , 0 ,0 ,0             ,(APTR)0 },
  92. { NM_ITEM ,  "About"                   ,"?",0 ,0             ,(APTR)MenAbout },
  93. { NM_ITEM ,  "About MUI"               , 0 ,0 ,0             ,(APTR)MenAboutMUI },
  94. { NM_ITEM ,  NM_BARLABEL               , 0 ,0 ,0             ,(APTR)0 },
  95. { NM_ITEM ,  "Quit"                    ,"Q",0 ,0             ,(APTR)MenQuit },
  96.  
  97. { NM_TITLE, "Settings"                 , 0 ,0 ,0             ,(APTR)0 },
  98. { NM_ITEM ,  "Mui..."                  , 0 ,0 ,0             ,(APTR)MenMUIPrefs },
  99.  
  100. { NM_END,NULL,0,0,0,(APTR)0 }
  101. };
  102.  
  103.  
  104. /**** Hooks ***/
  105.  
  106. const struct Hook aboutmuiHook = {
  107.    {NULL,NULL},
  108.    (void *)aboutmui,
  109.    NULL,NULL
  110. };
  111.  
  112. const struct Hook aboutHook = {
  113.    {NULL,NULL},
  114.    (void *)about,
  115.    NULL,NULL
  116. };
  117.  
  118. const struct Hook closeAboutHook = 
  119. {
  120.     {NULL,NULL},
  121.     (void *)closeabout,
  122.     NULL,NULL
  123. };
  124.  
  125.  
  126.  
  127.  
  128. /*** Main code ***/
  129.  
  130. int main(int argc,char ** argv)
  131. {
  132.     
  133.     /** A few variables. ctrlwin = main window, app = application object
  134.         menustrip = the programs menue, titlewin = the 'open while loading' window.
  135.         about button is the programs only gadget. */
  136.     
  137.     Object * ctrlwin, *app, *menustrip, *TitleWin;
  138.     Object *AboutButton;
  139.     Object *play, *stop, *noloop, *mainanimobj, *prop;
  140.     
  141.     /* Open muimaster library */
  142.     
  143.       if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  144.     {
  145.         printf("Unable to open muimaster.library\n");
  146.         return(5);
  147.     }
  148.     
  149.     /* Create apploication object */
  150.     /* I chose to make this a small thing with only a simple window with a text.
  151.         This way I can open the window quickly to confirm that the program is started.
  152.         Especially when the 'real' main windows contains alot of datatypes and other
  153.         'slow' stuff this makes sence. And especially on slow machines. */
  154.         
  155.     app=ApplicationObject,
  156.         MUIA_Application_Title    , progname,
  157.         MUIA_Application_Version    , "$VER: "progname" "vsion,
  158.         MUIA_Application_Copyright  , "©1998, Linus McCabe.",
  159.         MUIA_Application_Author     , "Linus McCabe",
  160.         MUIA_Application_Description, "TransferAnim.mcc example.", 
  161.         MUIA_Application_Base       , progbase,
  162.         MUIA_Application_Menustrip     , menustrip=MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
  163.     
  164.         SubWindow,TitleWin=WindowObject,
  165.             MUIA_Window_SizeGadget,FALSE,
  166.             MUIA_Window_DragBar,FALSE,
  167.             MUIA_Window_CloseGadget,FALSE,
  168.             MUIA_Window_DepthGadget,FALSE,
  169.  
  170.             MUIA_Window_Activate,FALSE,
  171.  
  172.             WindowContents,
  173.                 VGroup,
  174.                     Child,TextObject,
  175.                         MUIA_Text_Contents,"TransferAnim.mcc, \nMUI Customclass by Linus McCabe",
  176.                     End,
  177.                 End,
  178.             End,
  179.         End;
  180.         
  181.         if(app)    /* If the application could be opened */
  182.         {
  183.             
  184.             /* Open the title window */
  185.             set(TitleWin, MUIA_Window_Open, TRUE);    
  186.             
  187.             /* Create main window */
  188.             ctrlwin=WindowObject,
  189.                 MUIA_Window_Title,progname" "vsion" by Linus McCabe",
  190.                 MUIA_Window_ID   , MAKE_ID('M','A','I','N'),
  191.                 
  192.                 WindowContents,
  193.                     VGroup,
  194.                         MUIA_Background,"2:00000000,00000000,00000000",
  195.                         Child,HGroup,
  196.                             Child, mainanimobj=TransferAnimObject,
  197.                                 MUIA_TransferAnim_File, mainanim,
  198.                                 MUIA_InputMode,MUIV_InputMode_RelVerify,
  199.                             End,
  200.                             Child, TextObject,
  201.                                 MUIA_Text_SetMax,TRUE,
  202.                                 MUIA_Text_Contents,"\338"progname" "vsion"\nby Linus McCabe",
  203.                             End,
  204.                             Child, AboutButton=TransferAnimObject,
  205.                                             MUIA_TransferAnim_File,(ULONG) aboutbutton,
  206.                                             MUIA_TransferAnim_NoAnim,TRUE,
  207.                                             MUIA_InputMode,MUIV_InputMode_RelVerify,
  208.                                             MUIA_TransferAnim_SelectedFrame,1,
  209.                                             MUIA_TransferAnim_DisabledFrame,2,
  210.                             End,
  211.                         End,
  212.                         Child, HGroup,
  213.                             Child, play=TransferAnimObject,
  214.                                             MUIA_TransferAnim_File,(ULONG) playbutton,
  215.                                             MUIA_InputMode,MUIV_InputMode_RelVerify,
  216.                                             MUIA_TransferAnim_NoAnim,TRUE,
  217.                             End,
  218.                             Child, stop=TransferAnimObject,
  219.                                             MUIA_TransferAnim_File,(ULONG) stopbutton,
  220.                                             MUIA_InputMode,MUIV_InputMode_RelVerify,
  221.                                             MUIA_TransferAnim_NoAnim,TRUE,
  222.                             End,
  223.                             Child, noloop=TransferAnimObject,
  224.                                             MUIA_TransferAnim_File,(ULONG) checkmark,
  225.                                             MUIA_InputMode,MUIV_InputMode_Toggle,
  226.                                             MUIA_TransferAnim_NoAnim,TRUE,
  227.                             End,
  228.                             Child, prop=SliderObject,
  229.                                 MUIA_Group_Horiz, TRUE,
  230.                             End,
  231.                             
  232.                         End,
  233.                     End,
  234.                 End;
  235.     
  236.             if (ctrlwin)    /*If the creation was successful */
  237.             {
  238.                 
  239.                 ULONG tmp;
  240.                 
  241.                 /* add to application */
  242.                 DoMethod(app, OM_ADDMEMBER, ctrlwin);    
  243.     
  244.  
  245.             /*Main methods*/
  246.  
  247.             
  248.                 /* set up some basic notifiactions, closegadget, menues etc*/
  249.                 DoMethod(ctrlwin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  250.                 DoMethod(app,MUIM_Notify,MUIA_Application_MenuAction,MenQuit,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  251.                 DoMethod(app,MUIM_Notify,MUIA_Application_MenuAction,MenAbout,app,4,MUIM_CallHook,&aboutHook,menustrip,AboutButton);
  252.                 DoMethod(app,MUIM_Notify,MUIA_Application_MenuAction,MenAboutMUI,app,4,MUIM_CallHook,&aboutmuiHook,ctrlwin,menustrip);
  253.                 DoMethod(app,MUIM_Notify,MUIA_Application_MenuAction,MenMUIPrefs,app,2,MUIM_Application_OpenConfigWindow,0);
  254.  
  255.                 DoMethod(AboutButton,MUIM_Notify,MUIA_Pressed,FALSE,app,4,MUIM_CallHook,&aboutHook,menustrip,AboutButton);
  256.  
  257.                 DoMethod(play, MUIM_Notify, MUIA_Pressed, FALSE, mainanimobj, 1, MUIM_TransferAnim_StartAnim);
  258.                 DoMethod(stop, MUIM_Notify, MUIA_Pressed, FALSE, mainanimobj, 1, MUIM_TransferAnim_StopAnim);
  259.                 DoMethod(noloop, MUIM_Notify, MUIA_Selected, MUIV_EveryTime, mainanimobj, 3, MUIM_Set, MUIA_TransferAnim_NoLoop, MUIV_TriggerValue);
  260.  
  261.                 DoMethod(mainanimobj, MUIM_Notify, MUIA_TransferAnim_Frame, MUIV_EveryTime, prop, 3, MUIM_Set, MUIA_Slider_Level, MUIV_TriggerValue);
  262.                 DoMethod(prop, MUIM_Notify, MUIA_Slider_Level, MUIV_EveryTime, mainanimobj, 3, MUIM_Set, MUIA_TransferAnim_Frame, MUIV_TriggerValue);
  263.                 
  264.                 /* CLose the title win and open main window instead.
  265.                 On this little example, the title window only flashes if I
  266.                 do this, so I'll just let it remain open for now... */
  267.                 
  268. //                set(TitleWin,MUIA_Window_Open,FALSE);   
  269.                 set(ctrlwin,MUIA_Window_Open,TRUE);
  270.  
  271.                 get(mainanimobj, MUIA_TransferAnim_Frames, &tmp);
  272.                 set(prop, MUIA_Slider_Max, tmp);
  273.  
  274.                 /* The usual wait for exit loop */
  275.                 {
  276.                    ULONG sigs = 0;
  277.     
  278.                    while (DoMethod(app,MUIM_Application_NewInput,&sigs)    
  279.                       !=MUIV_Application_ReturnID_Quit)
  280.                    {
  281.                       if (sigs)
  282.                       {
  283.                          sigs = Wait(sigs | SIGBREAKF_CTRL_C);    
  284.                          if (sigs & SIGBREAKF_CTRL_C) break;        
  285.                       }
  286.                    }
  287.                 }
  288.  
  289.                 /* dispose the application and delete the customclass */
  290.                 MUI_DisposeObject(app); 
  291.             }
  292.         }
  293.     CloseLibrary(MUIMasterBase);
  294.     return(0);
  295. }
  296.  
  297.  
  298. /** Hooks code **/
  299.  
  300. __saveds __asm VOID aboutmui(
  301.     register __a0 struct Hook *hook ,
  302.     register __a2 Object *appl ,
  303.     register __a1 APTR *args )
  304. {
  305.  
  306.     APTR aboutwinMUI,menu;
  307.  
  308.  
  309.     /* create the mui about object */
  310.     
  311.     aboutwinMUI = AboutmuiObject,
  312.         MUIA_Window_RefWindow, args[0],
  313.         MUIA_Aboutmui_Application, appl,
  314.         End;
  315.     
  316.     
  317.     /*open if success */
  318.         
  319.     if (aboutwinMUI)
  320.         set(aboutwinMUI,MUIA_Window_Open,TRUE);
  321.     else
  322.         DisplayBeep(0);
  323.         
  324.     /* disable the menu entry */    
  325.         
  326.     menu=(APTR) DoMethod(args[1],MUIM_FindUData,MenAboutMUI);
  327.     set(menu,MUIA_Menuitem_Enabled,FALSE);
  328.  
  329.     /* enable it again when the window is closed */
  330.     
  331.     DoMethod(aboutwinMUI,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,menu,3,MUIM_Set,MUIA_Menuitem_Enabled,TRUE);
  332.  
  333. }
  334.  
  335. /* open and display our own aboutwindow */
  336.  
  337. __saveds __asm VOID about(
  338.     register __a0 struct Hook *hook ,
  339.     register __a2 Object *appl ,
  340.     register __a1 APTR *args)
  341. {
  342.     Object *portobj, *aboutwin,*menu; 
  343.     char string[155],*strp;
  344.     
  345.     /* create the object */
  346.     
  347.     aboutwin=WindowObject,
  348.         MUIA_Window_Title, "About",
  349.         MUIA_Window_ID   , MAKE_ID('B','O','U','T'),
  350.  
  351.         WindowContents,
  352.             VGroup,MUIA_Background,"2:00000000,00000000,00000000",
  353.                 Child, HGroup,
  354.                     Child, TransferAnimObject, 
  355.                         MUIA_TransferAnim_File, aboutanim,
  356.                     End,
  357.                     Child,HVSpace,
  358.                         Child, TextObject,
  359.                             MUIA_Text_Contents,"\338"progname" "vsion"\nby Linus McCabe",
  360.                         End,
  361.                     Child,HVSpace,
  362.                     Child, TransferAnimObject, 
  363.                         MUIA_TransferAnim_File, mainanim,
  364.                         MUIA_TransferAnim_ViewMode, MUIV_TransferAnim_Scale,
  365.                         MUIA_TransferAnim_ObjWidth, 50,
  366.                         MUIA_TransferAnim_ObjHeight, 50,
  367.                     End,
  368.                 End,
  369.                 Child,ScrollgroupObject,
  370.                     MUIA_Background,MUII_TextBack,
  371.                     MUIA_Scrollgroup_FreeHoriz,FALSE,
  372.                     MUIA_Scrollgroup_Contents,VirtgroupObject,
  373.                         VirtualFrame,
  374.                         Child,TextObject,
  375.                             MUIA_Text_Contents, "\n\33c\33b"progname"\n"vsion"\n",
  376.                         End,
  377.                         Child,TextObject,
  378.                             MUIA_Text_Contents, "\n\nMain coding by Linus McCabe\nCopyright © 1999 by Linus McCabe\n",
  379.                         End,
  380.                         Child,portobj=TextObject,
  381.                             MUIA_Text_Contents, "Arexx Port: Zensiba",    
  382.                         End,
  383.                         Child,BalanceObject,
  384.                         End,
  385.                         Child,TextObject,
  386.                             MUIA_Text_Contents, 
  387.                             "\n This is a small programming example in mui\n"\
  388.                             "to use TransferAnim.mcc, a mui customclass for display\n"\
  389.                             "of transferanimations.\n\n"\
  390.                             "\nThanx to\n\n"\
  391.                             "  Jessica, for bringing light to my life\n"\
  392.                             "  Ai, for being a good friend\n"\
  393.                             "  Märta, for being kind and helpful\n"\
  394.                             "  The folks at MUI mailinglist"\
  395.                             "\n\n"\
  396.                             "Greetings to\n\n"\
  397.                             "  TJOMME, Snipey, redpirk, MrXZY, _44\n"\
  398.                             "  GAZ, MazzleBoy, HighScore, RawHeadRex\n"\
  399.                             "  ChaoZer, MiLD, Tipop, AngelFire, UMBRO\n"\
  400.                             "  HarryO, Raven-X & Duff."\
  401.                             "\n\33l\n"\
  402.                             "Contact me at\n"\
  403.                             "Sparkle@hehe.com\n"\
  404.                             "www.come.to/sparkle\n"\
  405.                             "sparkle.amiga.tm\n\n"\
  406.                             "\33iThe program is released 'as is',\n"\
  407.                             "i e programmer or distributor takes no responsibility\n"\
  408.                             "to any loss of data or other damages this program may\n"\
  409.                             "cause.\n\n\33n",
  410.                         End,
  411.                     End,
  412.                 End,
  413.             End,
  414.         End;
  415.         
  416.     if(aboutwin)
  417.     {            
  418.         /* add the window to the application */
  419.         DoMethod(appl,OM_ADDMEMBER,aboutwin);
  420.         
  421.         /* call hook when closegadget is pressed */
  422.         DoMethod(aboutwin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,appl,5,MUIM_CallHook,&closeAboutHook,aboutwin,args[0],args[1]);
  423.  
  424.         /*get the arexx port */
  425.         get(appl,MUIA_Application_Base,&strp);
  426.         sprintf(&string[0],"\33cArexx Port: \33b%s\n",strp);
  427.         set(portobj,MUIA_Text_Contents,string);
  428.  
  429.         /* diable menu entry and gadget */
  430.         menu=(APTR) DoMethod(args[0],MUIM_FindUData,MenAbout);
  431.         set(menu,MUIA_Menuitem_Enabled,FALSE);
  432.         set(args[1],MUIA_Disabled,TRUE);
  433.  
  434.         /* open the window */
  435.         set(aboutwin,MUIA_Window_Open,TRUE);
  436.         
  437.     }
  438.  
  439. }
  440.  
  441.  
  442. /* hook to close the about window */
  443.  
  444. __saveds __asm VOID closeabout(
  445.     register __a0 struct Hook *hook ,
  446.     register __a2 Object *appl ,
  447.     register __a1 APTR *args)
  448. {
  449.  
  450.     APTR menu;
  451.     
  452.  
  453.     /* close the window */
  454.     set(args[0],MUIA_Window_Open,FALSE);
  455.     
  456.     /* remove the object from the application */
  457.     DoMethod(appl,OM_REMMEMBER,args[0]);
  458.  
  459.     /* dispose the object */
  460.     DoMethod(appl,MUIM_Application_PushMethod,args[0], 1,OM_DISPOSE);
  461.  
  462.     /* enable the menu and gadget again*/
  463.     menu=(APTR) DoMethod(args[1],MUIM_FindUData,MenAbout);
  464.     set(menu,MUIA_Menuitem_Enabled,TRUE);
  465.     set(args[2],MUIA_Disabled,FALSE);
  466. }
  467.  
  468.  
  469.  
  470.